#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
掌柜替换客服功能测试脚本
"""

from comment_processor import CommentProcessor

def test_shopkeeper_replacement():
    """测试掌柜替换客服功能"""
    print("=== 掌柜替换客服功能测试 ===")
    
    processor = CommentProcessor()
    
    # 测试用例
    test_cases = [
        # 基础替换测试
        ("掌柜服务很好", "客服服务很好"),
        ("掌柜态度不错", "客服态度不错"),
        ("掌柜回复很快", "客服回复很快"),
        ("掌柜很专业", "客服很专业"),
        ("掌柜很耐心", "客服很耐心"),
        
        # 复杂情况测试
        ("掌柜服务很好，态度不错", "客服服务很好，态度不错"),
        ("掌柜回复很快，很专业", "客服回复很快，很专业"),
        ("掌柜很耐心，推荐购买", "客服很耐心，推荐购买"),
        
        # 混合其他处理测试
        ("欢潮转珠棒掌柜服务很好😀", "客服服务很好"),
        ("在淘宝买的，掌柜态度不错❤️", "在买的，客服态度不错"),
        ("掌柜回复很快***", "客服回复很快"),
        ("掌柜很专业👍😊", "客服很专业"),
        
        # 边界情况测试
        ("掌柜", "客服"),
        ("掌柜掌柜", "客服客服"),
        ("掌柜掌柜掌柜", "客服客服客服"),
        ("没有掌柜的评论", "没有掌柜的评论"),
        ("", ""),
    ]
    
    print(f"{'原始文本':<30} {'处理后文本':<30} {'是否匹配':<10}")
    print("-" * 70)
    
    for i, (input_text, expected) in enumerate(test_cases, 1):
        # 测试完整处理流程
        result, info = processor.process_comment(input_text)
        is_match = result == expected
        
        print(f"{input_text:<30} {result:<30} {'✓' if is_match else '✗'}")
        
        if not is_match:
            print(f"  期望: {expected}")
    
    print("\n=== 单独测试掌柜替换功能 ===")
    
    # 单独测试掌柜替换功能
    shopkeeper_test_cases = [
        ("掌柜服务很好", "客服服务很好"),
        ("掌柜态度不错", "客服态度不错"),
        ("掌柜回复很快", "客服回复很快"),
        ("掌柜很专业", "客服很专业"),
        ("掌柜很耐心", "客服很耐心"),
        ("掌柜掌柜", "客服客服"),
        ("掌柜掌柜掌柜", "客服客服客服"),
    ]
    
    for input_text, expected in shopkeeper_test_cases:
        # 只测试错别字纠正功能（包含掌柜替换）
        result = processor.correct_typos(input_text)
        is_match = result == expected
        
        print(f"'{input_text}' -> '{result}' {'✓' if is_match else '✗'}")
        
        if not is_match:
            print(f"  期望: '{expected}'")

def test_complex_scenarios():
    """测试复杂场景"""
    print("\n=== 复杂场景测试 ===")
    
    processor = CommentProcessor()
    
    complex_test_cases = [
        "欢潮转珠棒掌柜服务很好😀***，，，，",
        "在淘宝买的，掌柜态度不错❤️",
        "掌柜回复很快*😊，值得购买👍",
        "掌柜很专业****👍😊，性价比高💯",
        "掌柜很耐心，推荐♥购买"
    ]
    
    for i, comment in enumerate(complex_test_cases, 1):
        print(f"\n测试 {i}: {comment}")
        
        processed_comment, info = processor.process_comment(comment)
        
        print(f"处理后: {processed_comment}")
        print(f"是否差评: {info['is_negative']}")
        print(f"是否重复: {info['is_duplicate']}")
        print(f"原始长度: {info['original_length']}")
        print(f"处理后长度: {info['processed_length']}")

def test_performance():
    """测试性能"""
    print("\n=== 性能测试 ===")
    
    processor = CommentProcessor()
    
    import time
    
    # 测试大量掌柜替换的性能
    test_text = "掌柜服务很好，掌柜态度不错，掌柜回复很快，掌柜很专业，掌柜很耐心"
    expected = "客服服务很好，客服态度不错，客服回复很快，客服很专业，客服很耐心"
    
    start_time = time.time()
    
    for i in range(1000):
        result = processor.correct_typos(test_text)
    
    end_time = time.time()
    
    print(f"1000次掌柜替换耗时: {end_time - start_time:.4f}秒")
    print(f"平均每次耗时: {(end_time - start_time) / 1000:.6f}秒")
    print(f"替换结果: {result}")
    print(f"结果正确: {'✓' if result == expected else '✗'}")

if __name__ == "__main__":
    test_shopkeeper_replacement()
    test_complex_scenarios()
    test_performance()
    print("\n掌柜替换客服功能测试完成！") 